package com.hzcx.app.simplechat.ui.chat.presenter;

import android.app.Activity;
import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.bean.UpLoadImgBean;
import com.hzcx.app.simplechat.model.ChatModel;
import com.hzcx.app.simplechat.model.FriendModel;
import com.hzcx.app.simplechat.model.GroupModel;
import com.hzcx.app.simplechat.model.HomeModel;
import com.hzcx.app.simplechat.model.MomentModel;
import com.hzcx.app.simplechat.model.PublicModel;
import com.hzcx.app.simplechat.model.UserModel;
import com.hzcx.app.simplechat.ui.chat.bean.ChatBottomAssistantMenuBean;
import com.hzcx.app.simplechat.ui.chat.bean.ChatQuickMsgBean;
import com.hzcx.app.simplechat.ui.chat.contract.ChatContract;
import com.hzcx.app.simplechat.ui.group.bean.GroupInfoBean;
import com.hzcx.app.simplechat.ui.main.bean.FriendRequestCountBean;
import com.hzcx.app.simplechat.ui.main.contract.MainContract;
import com.hzcx.app.simplechat.ui.moment.bean.NewMessageCountBean;
import com.hzcx.app.simplechat.ui.user.bean.UserInfoBean;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.util.List;

public class ChatPresenter extends BasePresenter<ChatContract.View> implements ChatContract.Presenter {

    /**
     * 获取群组信息
     *
     * @param context
     * @param groupID
     */
    @Override
    public void getGroupInfo(Context context, String groupID) {
        GroupModel.getGroupInfo(context, groupID, new BaseObserver<GroupInfoBean>() {
            @Override
            protected void onSuccess(GroupInfoBean data) {
                if (mView!=null){
                    mView.groupInfo(data);
                }
            }
        });
    }

    /**
     * 获取用户信息
     *
     * @param context
     * @param id
     */
    @Override
    public void getUserInfo(Context context, int id, int tag, boolean isShow) {
        UserModel.getUserInfo(context, id, new BaseDialogObserver<UserInfoBean>(context, isShow) {
            @Override
            protected void onSuccess(UserInfoBean data) {
                mView.userInfoResult(data, tag);
            }
        });
    }

    /**
     * 添加收藏
     *
     * @param context
     * @param collectdetail
     * @param collectimage
     * @param member_id
     */
    @Override
    public void addChatCollect(Context context, String collectdetail, String collectimage, int member_id) {
        HomeModel.addChatCollect(context, collectdetail, collectimage, member_id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.collectSuccess();
            }
        });
    }

    /**
     * 上传图片
     *
     * @param path
     * @param id
     */
    @Override
    public void upLoadImg(Activity activity, String path, int id) {
        PublicModel.upLoadImg(activity, TokenUtils.getTokenHeader(), path, new BaseDialogObserver<UpLoadImgBean>(activity) {
            @Override
            protected void onSuccess(UpLoadImgBean data) {
                mView.upLoadImgSuccess(data, id);
            }
        });
    }

    /**
     * 获取快捷回复列表
     *
     * @param context
     */
    @Override
    public void getChatQuickMsgList(Context context) {
        ChatModel.getChatQuickMsgList(context, new BaseObserver<List<ChatQuickMsgBean>>() {
            @Override
            protected void onSuccess(List<ChatQuickMsgBean> data) {
                mView.qucikMsgResult(data);
            }
        });
    }

    /**
     *  给官方客服号发消息
     * @param context
     */
    @Override
    public void sendCustomServiceMsg(Context context) {
        ChatModel.sendCustomServiceMsg(context, new BaseObserver<BaseEmptyBean>() {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.sendCustomServiceSuccess();
            }
        });
    }

    /**
     *  获取官方底部菜单消息
     * @param context
     */
    @Override
    public void getChatBottomAssistantMenu(Context context) {
        ChatModel.getChatBottomAssistantMenu(context, new BaseObserver<List<ChatBottomAssistantMenuBean>>() {
            @Override
            protected void onSuccess(List<ChatBottomAssistantMenuBean> data) {
                mView.chatBottomAssistantMenuResult(data);
            }
        });
    }

    /**
     *  根据菜单ID获取官方消息
     */
    @Override
    public void getChatAssistantMessage(Context context,String type,int push_id) {
        ChatModel.getChatAssistantMessage(context, type, push_id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.getAssistantMsgSuccess();
            }
        });
    }

    /**
     *  根据二维码获取用户信息
     * @param context
     * @param url
     */
    @Override
    public void getUserInfoByQrCode(Context context, String url) {
        UserModel.getUserInfoByQrCode(context, url, new BaseDialogObserver<UserInfoBean>(context) {
            @Override
            protected void onSuccess(UserInfoBean data) {
                mView.userInfoResult(data);
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {
                super.onFailure(e, errorMsg);
                mView.onFail();
            }
        });
    }
}
